;; The first four lines of this file were added by Dracula.
;; They tell DrScheme that this is a Dracula Modular ACL2 program.
;; Leave these lines unchanged so that DrScheme can properly load this file.
#reader(planet "reader.rkt" ("cce" "dracula.plt") "modular" "lang")
(require "Igpa-criterion.lisp")
(require "Iformulas-aux.lisp")
(require "Ilist.lisp")
(require "Itranspose-fast.lisp")

(module Mgpa-criterion
  
(import Iformulas-aux)
(import Ilist)
(import Itranspose-fast)
  
(include-book "list-utilities" :dir :teachpacks)

(defconst *MIN-GPA* 2)
(defconst *MAX-GPA* 4)
(defconst *GPA-GAP/2* 0.125)
(defconst *CONVERTED-GRADE-LENGTH*
  (/ (- *MAX-GPA* *MIN-GPA*) (* *GPA-GAP/2* 2))) 

(defun convert-gpa
  (gpa)
  (round (/ (- gpa *MIN-GPA*) *GPA-GAP/2*) 2))

(defun get-list-of-team-member-converted-gpa-aux
  (list-of-team-member-gpa)
  (if (consp list-of-team-member-gpa)
      (cons (update-nth (convert-gpa (car list-of-team-member-gpa))
                        1
                        (replicate *CONVERTED-GRADE-LENGTH* 0))
            (get-list-of-team-member-converted-gpa-aux
             (cdr list-of-team-member-gpa)))
      nil))

(defun get-list-of-team-member-converted-gpa
  (list-of-all-team-member-data-by-criterion)
  (if (consp list-of-all-team-member-data-by-criterion)
      (get-list-of-team-member-converted-gpa-aux
       (caddr list-of-all-team-member-data-by-criterion))
      nil))

(defun calculate-team-gpa-score-aux
  (list-of-team-member-converted-gpa-transpose)
  (if (consp list-of-team-member-converted-gpa-transpose)
      (cons
       (binary-or (car list-of-team-member-converted-gpa-transpose))
       (calculate-team-gpa-score-aux
        (cdr list-of-team-member-converted-gpa-transpose)))
      nil))

(defun calculate-team-gpa-score
  (list-of-all-team-member-data-by-criterion num-of-members gpa-weight)
  (if (not (or (endp list-of-all-team-member-data-by-criterion)
               (zerop gpa-weight)))
      (*
       (/
        (sumlist (calculate-team-gpa-score-aux
                   (transpose-fast
                    (get-list-of-team-member-converted-gpa
                     list-of-all-team-member-data-by-criterion))))
        num-of-members)
       gpa-weight)
      0))

  (export Igpa-criterion))

